package com.lcc.springconfig.config;

import com.lcc.springconfig.model.User;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.annotation.ApplicationScope;
import org.springframework.web.context.annotation.SessionScope;

@Configuration
public class beanConfig {

    @Bean
    public User user(){
        return new User(1,"zhangsan");
    }
    //单例作用域
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    @Bean
    public User singleUser(){
        return new User();
    }

    //多例行为模式
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @Bean
    public User protoTypeUser(){
        return new User();
    }
    //Request行为模式
    @Scope(value = WebApplicationContext.SCOPE_REQUEST,proxyMode = ScopedProxyMode.TARGET_CLASS)
    @Bean
    public User requestUser(){
        return new User();
    }

    //session行为模式
    @SessionScope
    @Bean
    public User sessionUser(){
        return new User();
    }

    //Application行为模式
    @ApplicationScope
    @Bean
    public User applicationUser(){
        return new User();
    }
}
